
//print
$(".btn-print").click(function(){
	$(".nav-tabs").hide();
	window.print();
	$(".nav-tabs").show();
});
//按年 统计  
function callbackByYear(target, retdata, datetime){
	//按月显示统计信息
		var data1 = retdata.datayear;
		var sum=0;
		for (var index in data1[0]) {
			data1[0][index] = data1[0][index] + "月";
			sum += data1[1][index];
		}
		if(sum==0){
			alert("暂无数据");
			return false;
		}
		target.find("div[name='sum']").html("<center>收费员用户总量：<font color=red> "+sum+" </font></center>");
		drawMapByMonth( $(target).find(".map>div[name=map1]"), data1, datetime+ " 年  收费员用户总量发展趋势","按年统计", "月");
		
		var data2 = retdata.datayears;
		var sum1=0;
		for (var indexs in data2[0]) {
			data2[0][indexs] = data2[0][indexs] + "月";
			sum1 += data2[1][indexs];
		}
		if(sum1==0){
			alert("暂无数据");
			return false;
		}
		target.find("div[name='sum1']").html("<center>司机用户总量：<font color=red> "+sum1+" </font></center>");
		drawMapByMonthsiji( $(target).find(".map>div[name=map2]"), data2, datetime+ " 年  司机用户总量发展趋势","按年统计", "月");
}
//按月 统计  
function callbackByMonth(target, retdata, datetime){
		//按天显示统计信息
		var data1 = retdata.datamonth;
		var sum=0;
		for(var index in data1[0]){
			data1[0][index] = data1[0][index] + "号";
			sum += data1[1][index];
		}
		if(sum==0){
			alert("暂无数据");
			return false;
		}
		target.find("div[name='sum']").html("<center>收费员用户总量：<font color=red> "+sum+" </font></center>");
		drawMapByMonth( $(target).find(".map>div[name=map1]"), data1, datetime+" 月  收费员用户总量发展趋势","按月统计", "日");
		
		var data2 = retdata.datamonths;
		var sum1=0;
		for(var inde in data2[0]){
			data2[0][inde] = data2[0][inde] + "号";
			sum1 += data2[1][inde];
		}
		if(sum1==0){
			alert("暂无数据");
			return false;
		}
		target.find("div[name='sum1']").html("<center>司机用户总量：<font color=red> "+sum1+" </font></center>");
		drawMapByMonthsiji( $(target).find(".map>div[name=map2]"), data2, datetime+" 月  司机用户总量发展趋势","按月统计", "日");
}

//费员用户总量
function drawMapByMonth(obj, data, title, name, unitName){
	obj.highcharts({
			exporting:{
				enabled: false
			},
		 	chart: {
	            type: 'area',
	            zoomType: 'x'
	        },
	        title: {
	            text: title
	        },
	        subtitle: {
	            text: name
	        },
	        xAxis: {
        	   title: {
	              text: '日期'
	           },
	           allowDecimals: false,
	           minTickInterval: 1,
	   //        categories: data[0],
	           labels: {
	                formatter: function() {
	                    return this.value + unitName;
	                }
	            }
	        },
	        yAxis: {
	            title: {
	                text: '数量 '
	            },
	            labels: {
	                formatter: function() {
	                    return this.value +'个';
	                }
	            }
	        },
	        tooltip: {
	            crosshairs: true,
	            shared: true,  
	            headerFormat: '<span style="color:red">{point.key}'+ unitName +'</span>  ', 
	            pointFormat: ' : <b>{point.y} 个  </b>' //'{series.name}: <b>{point.y} 个  </b>
	        },
	        plotOptions: {
	            area: {
	                fillColor: {
	                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
	                    stops: [
	                        [0, Highcharts.getOptions().colors[0]],
	                        [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
	                    ]
	                },
	                marker: {
	                    radius: 1
	                },
	                lineWidth: 1,
	                states: {
	                    hover: {
	                        lineWidth: 1
	                    }
	                },
	                threshold: null
	            }
	        },
	        series: [{
	        	 name: '收费员用户总量发展趋势',
	        	 pointInterval: 1,
		         pointStart: 1,
		         data: data[1]
	        }]
    });
}


//司机用户总量发展趋势
function drawMapByMonthsiji(obj, data, title, name, unitName){
	obj.highcharts({
		 	exporting:{
				enabled: false
			},
		 	chart: {
	            type: 'area',
	            zoomType: 'x'
	        },
	        title: {
	            text: title
	        },
	        subtitle: {
	            text: name
	        },
	        xAxis: {
        	   title: {
	              text: '日期'
	           },
	           allowDecimals: false,
	           minTickInterval: 1,
	    //       categories: data[0],
	           labels: {
	                formatter: function() {
	                    return this.value + unitName ;
	                }
	            }
	        },
	        yAxis: {
	            title: {
	                text: '数量 '
	            },
	            labels: {
	                formatter: function() {
	                    return this.value +'个';
	                }
	            }
	        },
	        tooltip: {
	            crosshairs: true,
	            shared: true,  
	            headerFormat: '<span style="color:red">{point.key}'+ unitName +'</span>  ', 
	            pointFormat: ' : <b>{point.y} 个  </b>'  //{series.name}: <b>{point.y} 个  </b>
	        },
	        plotOptions: {
	            area: {
	                fillColor: {
	                    linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
	                    stops: [
	                        [0, Highcharts.getOptions().colors[0]],
	                        [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
	                    ]
	                },
	                marker: {
	                    radius: 1
	                },
	                lineWidth: 1,
	                states: {
	                    hover: {
	                        lineWidth: 1
	                    }
	                },
	                threshold: null
	            }
	        },
	        series: [{
	        	 name: '司机用户总量发展趋势',
	        	 pointInterval: 1,
		         pointStart: 1,
		         data: data[1]
	        }]
    });
}

$("div.container>div.row input[type='button']").click(function(){
	var stattype = $(this).attr("stattype");
	var stattypefor = $(this).attr("for");
	var callbackMap = $(this).attr("callback");
	var target = $(this).parent().parent();
	var datetime = $("#"+stattypefor).val();
	if(window.console){
		console.log("stattype="+stattype+" stattypefor="+stattypefor);
	}
	var data={
			stattype: stattype,
			datetime: datetime
		};
 
	startMask();//等待提示开启

	$.ajax({
		type: 'POST',
		url: "StatCumulativeUserAction?method=query&querytype=json",
		data: data,
		success: function(retdata){
			
			endMask();//等待提示关闭
			
			if(window.console){
				console.log(retdata);
			}
			
			if(retdata.error==-100){
				alert( retdata.msg );
				//window.top.location = retdata.url;
			}else{
				if(retdata.error==0){
					window[callbackMap]( target, retdata, datetime );
				}else{
					alert( retdata.msg );
				}
			}
	  	},
		dataType: "json",
		error : function(XMLHttpRequest, textStatus, errorThrown){
			alert( XMLHttpRequest.responseText);
			endMask();//等待提示关闭
			$("#errorFiled").html( XMLHttpRequest.responseText );
			$("#errorFiled").show();
		}
	});
});

function switchtab( tabtype ){
	$("div.container>div.row").hide();
	$("div.container>div.row[type='"+tabtype+"']").show() ;
	if(window.console){
		//console.log("switchtab @ "+tabtype);
	}
}

$("ul.nav-tabs li").mouseover(function(){
	var tab = $(this);
	var nav = tab.parent();
	$(nav).children("li").removeClass("active");
	tab.addClass("active");
	var type = $(this).attr("type");
	switchtab(type);
	return true;
});

